﻿using BCCommon.Enums;
using BCCommon.PaymentEnums;
using BCEntity.Common.Payment.Payment;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace BCData.Common.Payment.Payment
{
    /// <summary>
    /// 支付记录
    /// </summary>
    public interface IPaymentRecordData
    {
        /// <summary>
        /// 创建支付记录
        /// </summary>
        /// <param name="payChannelType">支付渠道类型</param>
        /// <param name="orderType">订单类型</param>
        /// <param name="subject">订单标题</param>
        /// <param name="referenceNumber">引用编号（订单编号）</param>
        /// <param name="amount">金额</param>
        /// <param name="userId">用户Id</param>
        /// <param name="appType">应用类型</param>
        /// <param name="osType">系统类型</param>
        /// <param name="payer">付款人</param>
        /// <param name="appId">应用账号</param>
        /// <param name="adminId">操作人Id</param>
        /// <param name="adminFullName">操作人姓名</param>
        /// <param name="operationType">操作类型</param>
        /// <param name="flowDirection">资金流向</param>
        /// <returns></returns>
        PaymentRecordEntity Create(PaymentChannelType payChannelType, string orderType, string subject, string referenceNumber, decimal amount,
            long? userId, SourceAppType appType, SourceOSType osType, SourcePayerType? payer, string appId = null, long? adminId=null, string adminFullName= null, string operationType = null,
            SourceFlowDirectionType? flowDirection = SourceFlowDirectionType.Income);
        /// <summary>
        /// 设置必要行为
        /// </summary>
        /// <param name="paymentRecordId">支付记录Id</param>
        /// <returns></returns>
        PaymentRecordEntity SetAsRequireAction(long paymentRecordId);
     
        /// <summary>
        /// 设置成功
        /// </summary>
        /// <param name="paymentRecordId">支付记录Id</param>
        /// <returns></returns>
        PaymentRecordEntity SetAsSuccess(long paymentRecordId);
     
        /// <summary>
        /// 设置签名时间
        /// </summary>
        /// <param name="paymentRecordId">支付记录Id</param>
        /// <returns></returns>
        PaymentRecordEntity SetAsSignTime(long paymentRecordId);
       
        /// <summary>
        /// 设置失败
        /// </summary>
        /// <param name="paymentRecordId">支付记录Id</param>
        /// <param name="remark">失败原因。</param>
        /// <returns></returns>
        PaymentRecordEntity SetAsFailed(long paymentRecordId, string remark);
        /// <summary>
        /// 修改退款操作状态
        /// </summary>
        /// <param name="paymentRecordId">支付记录Id</param>
        /// <returns></returns>
        Task<PaymentRecordEntity> UpdateRefundOperationType(long paymentRecordId);
        /// <summary>
        /// 设置待确认
        /// </summary>
        /// <param name="paymentRecordId">支付记录Id</param>
        /// <returns></returns>
        PaymentRecordEntity SetAsToBeConfirmed(long paymentRecordId);
      
        /// <summary>
        /// 获取支付记录单条
        /// </summary>
        /// <param name="paymentRecordId">支付记录Id</param>
        /// <returns></returns>
        PaymentRecordEntity GetPaymentRecordByPaymentRecordId(long paymentRecordId);

        /// <summary>
        /// 获取支付记录列表
        /// </summary>
        /// <param name="orderType">订单类型</param>
        /// <param name="referenceNumber">订单编号</param>
        /// <returns></returns>
        IEnumerable<PaymentRecordEntity> GetPaymentRecordsByReferenceNumber(FlowType? orderType, string referenceNumber);

        /// <summary>
        /// 获取支付记录列表
        /// </summary>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页大小</param>
        ///  <param name="dataCount">数据总条数</param>
        /// <param name="userId">用户ID</param>
        /// <returns></returns>
        IEnumerable<PaymentRecordEntity> GetPaymentRecordsByUserId(int pageIndex, int pageSize, out int dataCount, long userId);

        /// <summary>
        /// 获取支付记录列表
        /// </summary>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页大小</param>
        ///  <param name="dataCount">数据总条数</param>
        /// <param name="userId">用户ID</param>
        /// <returns></returns>
        IEnumerable<PaymentRecordEntity> GetPaymentRecordsByAgentRecordId(int pageIndex, int pageSize, out int dataCount, long agentRecordId);

        /// <summary>
        /// 获取支付总金额
        /// </summary>
        /// <param name="provinceId">身份Id</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <returns></returns>
        decimal GetPaymentTotal(string provinceId, DateTime? start, DateTime? end);
       
        /// <summary>
        /// 获取最新的一条支付记录
        /// </summary>
        /// <param name="referenceNumber">订单编号</param>
        /// <returns></returns>
        Task<PaymentRecordEntity> GetLatestByReferenceNumberAsync(string referenceNumber);
      
        /// <summary>
        /// 获取支付成功记录信息
        /// </summary>
        /// <param name="userName">客户姓名</param>
        /// <param name="phone">手机号</param>
        /// <param name="appType">App类型</param>
        /// <param name="orderType">订单类型</param>
        /// <param name="payChannelType">支付渠道</param>
        /// <param name="start">支付开始时间</param>
        /// <param name="end">支付结束时间</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <param name="paymentStatus"></param>
        /// <returns></returns>
        Task<(IEnumerable<PaymentRecordUserViewEntity>, int)> Query(string userName, string phone, SourceAppType? appType, FlowType? orderType, PaymentChannelType? payChannelType, DateTime? start, DateTime? end, int? pageIndex, int? pageSize, PaymentResultType? paymentStatus = PaymentResultType.Success);
       
        /// <summary>
        /// 获取成功记录
        /// </summary>
        /// <param name="referenceNumber">订单编号</param>
        /// <returns></returns>
        Task<PaymentRecordBillViewEntity> GetSuccessByReferenceNumberAsync(string referenceNumber);
       
        /// <summary>
        /// 获取非退款成功记录
        /// </summary>
        /// <param name="referenceNumber">订单编号</param>
        /// <returns></returns>
        Task<PaymentRecordBillViewEntity> GetNoRefundSuccessByReferenceNumberAsync(string referenceNumber);
        /// <summary>
        /// 修改退款成功标记
        /// </summary>
        /// <param name="paymentRecordId">支付记录Id</param>
        /// <returns></returns>
        Task<PaymentRecordEntity> UpdateRefundSuccess(long paymentRecordId);
        /// <summary>
        /// 获取记录列表
        /// </summary>
        /// <param name="referenceNumber">引用编号</param>
        /// <returns></returns>
        Task<IEnumerable<PaymentRecordEntity>> GetEntityByReferenceNumberAsync(string referenceNumber);
        /// <summary>
        /// 获取退款记录
        /// </summary>
        /// <param name="referenceNumber">引用编号</param>
        Task<PaymentRecordEntity> GetRefundPaymentRecord(string referenceNumber);

        /// <summary>
        /// 更新支付成功
        /// </summary>
        /// <param name="paymentRecordId">支付记录Id</param>
        /// <returns></returns>
        Task<bool> UpdateSuccessByIdAsync(long paymentRecordId);

        /// <summary>
        /// 获取支付记录列表
        /// </summary>
        /// <param name="referenceNumber">引用编号</param>
        /// <param name="paymentChannelType">支付渠道类型</param>
        /// <returns></returns>
        Task<IEnumerable<PaymentRecordEntity>> GetPaymentRecordsByReferenceNumber(string referenceNumber, PaymentChannelType paymentChannelType);

        /// <summary>
        /// 获取支付记录列表
        /// </summary>
        /// <param name="referenceNumberList">引用编号</param>
        /// <returns></returns>
        Task<IEnumerable<PaymentRecordEntity>> GetListByReferenceNumberAsync(List<string> referenceNumberList);
    }
}
